#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

void test()
{
    vector<int> vec;
    vec.push_back(100);//size = 1, capacity = 1
    bool flag = true;

    for(auto it = vec.begin(); it != vec.end(); ++it)
    {
        cout << *it << "  ";
        if(flag)
        {
            //底层已经发生了扩容操作
            //迭代器已经失效了
            vec.push_back(200);//size = 2, capacity = 2
            flag = false;
            it = vec.begin();//重置迭代器的位置
        }
    }
    cout << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

